import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mac
 * Date: 2022-08-25
 * Time: 15:23
 */

//3.课后作业1
class Calculator{
    private int num1;
    private int num2;

    public int getNum1() {
        return num1;
    }

    public void setNum1(int num1) {
        this.num1 = num1;
    }

    public int getNum2() {
        return num2;
    }

    public void setNum2(int num2) {
        this.num2 = num2;
    }

    public int add() {
        return num1 + num2;
    }
    public int sub() {
        return num1 - num2;
    }
    public int mul() {
        return num1 * num2;
    }
    public double dev(){
        return num1 * 1.0 / num2;
    }
}

//4.课后作业3
class MyValue {
    public int val;
}
public class ClassWork {
    //1.奇数偶数换位
    public static void exchArray(int[] array){
        int left = 0;
        int right = array.length - 1;
        while (left < right){
            while (left < right && array[left] % 2 == 0){
                left++;
            }
            while (left < right && array[right] % 2 != 0){
                right--;
            }

            int tmp = array[left];
            array[left] = array[right];
            array[right] = tmp;
            left++;
            right--;
        }
    }
    public static void main1(String[] args) {
        int[] array = { 1,2,3,4,5,6,7,8,9 };
        exchArray(array);
        System.out.println(Arrays.toString(array));
    }

    //2.交换数组
    public static void main2(String[] args) {
        int[] array1 = { 1,2,3,4,5 };
        int[] array2 = { 5,4,3,2,1 };
        System.out.println("交换前：");
        System.out.println("array1:" + Arrays.toString(array1));
        System.out.println("array2:" + Arrays.toString(array2));
        for (int i = 0; i < array1.length; i++) {
            int tmp = array1[i];
            array1[i] = array2[i];
            array2[i] = tmp;
        }
        System.out.println("交换后：");
        System.out.println("array1:" + Arrays.toString(array1));
        System.out.println("array2:" + Arrays.toString(array2));
    }

    //3.课后作业1
    public static void main3(String[] args) {
        Calculator calculator = new Calculator();
        calculator.setNum1(1);
        calculator.setNum2(2);
        System.out.println(calculator.add());
    }

    //4.课后作业3
    public static void swap(MyValue myV1, MyValue myV2){
        int tmp = myV1.val;
        myV1.val = myV2.val;
        myV2.val = tmp;
    }
    public static void main(String[] args) {
        MyValue myValue1 = new MyValue();
        myValue1.val = 10;
        MyValue myValue2 = new MyValue();
        myValue2.val = 20;

        System.out.println(myValue1.val + " " + myValue2.val);
        swap(myValue1, myValue2);
        System.out.println(myValue1.val + " " + myValue2.val);
    }
}
